package 第二章实用类作业;
import java.text.SimpleDateFormat;
import java.util.Calendar;
    public class TestCalender
    {
        public static void main(String[] args)
        {
            Calendar now = Calendar.getInstance();
            int year = now.get(Calendar.YEAR);
            for(int i=2000;i<year+1;i++)
            {
                System.out.println(getDate(i,6,3,0));
            }
        }
        public static String getDate(int year,int month,int weekOfmonth,int dayofweek)
        {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
//得到当年当月1号的日子
            c.set(year, month-1, 1);
//得出当年当月1号是星期几（日，一，二，三，四，五，六）
//周日是1
            int weekday = c.get(Calendar.DAY_OF_WEEK);
//计算该月总天数
            int countDay = 0;
            if(weekday==1)
            {
                countDay = (weekOfmonth-1)*7 + dayofweek+1;
            }
            else
            {
                countDay = (weekOfmonth-1)*7 + 7-weekday+1 + dayofweek+1;
            }
            c.set(Calendar.DAY_OF_MONTH, countDay);
            String dateStr = sdf.format(c.getTime());
            return dateStr;
        }
    }


